﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<EasyQuartz.Web.ViewModels.JobListViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
	<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
	<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
	<script src="/Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
	<script type="text/javascript">
		// Function update.
		function handleUpdate(context) {
			// Load and deserialize the returned JSON data
			var json = context.get_data();
			var data = Sys.Serialization.JavaScriptSerializer.deserialize(json);

			// Update the page elements
			$('#update-message').text("Running job... =>" + data.Name).fadeOut(2000, null);

			getWhatever();
		}

		function getWhatever() {
			var strUrl = "/Job/"; //whatever URL you need to call
			var strReturn = "";
			jQuery.ajax({
				url: strUrl, success: function (html) { strReturn = html; }, async: false
			});
			return strReturn;
		}

	</script>
	<h2>
		Jobs List</h2>
	<table id="jobs-Table" width="100%">
		<tr>
			<th>
				What do you do?
			</th>
			<th>
				Name
			</th>
			<th>
				Group
			</th>
			<th>
				Type
			</th>
		</tr>
		<% foreach (var item in Model.Jobs)
	 { %>
		<tr id="jobs-values">
			<td>
				<%: Ajax.ActionLink("Execute Now", "RunNow",
					new { jobName = item.Name, jobGroup = item.Group },
					new AjaxOptions
					{
						HttpMethod = "Post",		
						OnSuccess = "handleUpdate",
						Confirm = string.Format("Are you sure to execute {0}?", item.Name)
					})%>
				<%: Html.ActionLink("Remove", "Remove", new {jobName = item.Name, jobGroup = item.Group}) %>
			</td>
			<td>
				<%: item.Name %>
			</td>
			<td>
				<%: item.Group %>
			</td>
			<td>
				<%: item.Type %>
			</td>
		</tr>
		<% } %>
	</table>
	<div id="update-message">
	</div>
</asp:Content>
